unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  arr : array of TButton;
  turn: integer;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var i: integer;
begin
    setlength (arr, 900);
    for i := 0 to 899 do
    begin
    arr[i] := TButton.Create(Form1);
    arr[i].Parent := Form1;
    arr[i].Width := 20;
    arr[i].Height := 20;
    arr[i].Parent := Form1;
    arr[i].Top := 20*(i div 30);
    arr[i].Left := 20*(i mod 30);
    arr[i].OnClick := Button2Click;
    turn:= 0;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  i: integer;
begin
  for i := 0 to 899 do
  begin
    if (Sender = arr[i]) then
    begin
      if (turn mod 2 = 0) then
      begin
        arr[i].Caption := 'X';
        arr[i].Enabled:= false;
      end else begin
        arr[i].Caption := 'O';
        arr[i].Enabled:= false;
      end;
    end;
  end;
  turn:= turn+1;
end;
end.
